{- -}
module XI.ExchangeProfile where
import Text.XML.Light.Types
import Text.XML.Light (parseXMLDoc)
import Text.XML.Light.Proc
import Data.Maybe

type SectionName = String
type ParameterName = String
type Since = String
type Type = String
type Description = String
type Value = String

data AiiParameter = AiiParameter ParameterName Since Type Description Value deriving (Eq, Show)
data AiiTree = AiiSection SectionName [AiiTree] [AiiParameter] 
    deriving (Eq, Show)
--data AiiRoot = [AiiSection] deriving (Eq, Show)
   
sample_parameters = [AiiParameter "com.sap.aii.util.xml.parserFactory" "1.0*" "string"
    "SAX-Parser and XSLT-Transformer used internally. This does not influence the Mapping-Runtime!"
    "com.sap.engine.lib.jaxp.SAXParserFactoryImpl"
    , AiiParameter "com.sap.aii.util.xml.transformerFactory" "1.0*" "string"
    "SAX-Parser and XSLT-Transformer used internally. This does not influence the Mapping-Runtime!"
    "com.sap.engine.lib.jaxp.TransformerFactoryImpl"
    , AiiParameter "com.sap.aii.util.xml.schemaValidator" "3.0" "string"
    "Class name of the schema validator."
    "com.sap.engine.lib.schema.validator.SchemaValidator"
    ]

sample_tree :: AiiTree
sample_tree = AiiSection "default" 
    [AiiSection "Default.XML" [] sample_parameters
    , AiiSection "Default.DatabaseSettings" [] [] ] []

parseProfile :: String -> [AiiTree]
parseProfile str = case doc of
    Nothing -> [] -- todo raise warning "no xml"
    Just root
        | (qName $ elName root) == "aiiparameters" -> locparse root
        | True -> [] -- todo raise warning "wrong xml"
    where 
        doc = parseXMLDoc str
        te = onlyElems . elContent
        --te root = elContent . onlyElems $ root
        locparse root = map parseAiiXml $ te root

filterElements :: String -> [Element] -> [Element]
filterElements name es = filter (filterElement (\x -> (qName (elName x)) == name )) es
        
parseAiiXml :: Element -> AiiTree
parseAiiXml c = AiiSection "" [] []
    --where 
        --(qName $ elName c) == "section" ->  AiiSection "" [] []

sampleProfile :: [AiiTree]
sampleProfile = [sample_tree]

